#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
const int N=1e5+10,INF=0x3f3f3f3f;
int f[N];
int n,m;
vector<int> fun(int x)
{
	vector<int>ans;
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			ans.push_back(i);
			if(i!=x/i){
				ans.push_back(x/i);
			}
		}
	}
	
	return ans;
}
int main()
{
	cin>>n>>m;
	memset(f,0x3f,sizeof(f));
	f[n]=0;
	for(int i=n;i<=m;i++){
		if(f[i]!=INF){
			vector<int>ans=fun(i);
			for(int x:ans){
				if(i+x<=m){
					f[i+x]=min(f[i+x],f[i]+1);
				}
			}
		}
	}
	if(f[m]==INF)cout<<-1<<endl;
	else cout<<f[m]<<endl;
	return 0;
}
